﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_Common;
using System.Data;
using V5_BLL;
using V5_Model;

namespace V5_EShop.Admin
{
    public partial class Admin_ProductAnswer : System.Web.UI.Page
    {
        int askID = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            askID = Input.SetInt(Request["askid"]);
            if (!this.IsPostBack)
            {
                Bind_gvList();
            }
        }


        private void Bind_gvList()
        {
            this.MultiViewList.ActiveViewIndex = 0;
            int Count = 0;
            string strWhere = " askid=" + Utils.FilterInjection(askID);

            DataTable dt = new BLLProductAnswer().GetList(

                Pager.PageSize,
                Pager.CurrentPageIndex,
                strWhere,
                ref Count).Tables[0];
            this.Pager.RecordCount = Count;
            this.gvList.DataSource = dt;

            this.gvList.DataBind();
        }


        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="oUserID"></param>
        /// <returns></returns>
        public ModelUser Get_User(object oUserID)
        {
            int UserID = Input.SetInt(oUserID);
            if (UserID > 0)
            {
                return new BLLUser().GetModel(UserID);
            }
            return null;
        }

        /// <summary>
        /// 获取产品信息
        /// </summary>
        /// <param name="oProductID"></param>
        /// <returns></returns>
        public ModelProduct Get_Product(object oProductID)
        {
            int ProductID = Input.SetInt(oProductID);
            if (ProductID > 0)
            {
                return new BLLProduct().GetModel(ProductID);
            }
            return null;
        }

        protected void Pager_PageChanged(object sender, EventArgs e)
        {
            this.Bind_gvList();
        }

        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string eName = Input.SetString(e.CommandName);
            int id = Input.SetInt(e.CommandArgument);
            switch (eName.ToLower())
            {
                case "passed":
                    Bind_Passed(id);
                    break;
                case "del":
                    Bind_Delete(id);
                    break;
                default:
                    break;
            }
        }

        private void Bind_Passed(int id)
        {
            ModelProductAnswer model = new BLLProductAnswer().GetModel(id);
            if (model != null)
            {
                if (model.Passed == 1)
                {
                    model.Passed = 0;
                }
                else
                {
                    model.Passed = 1;
                }
                new BLLProductAnswer().Update(model);
            }
            this.Bind_gvList();
        }

        private void Bind_Delete(int id)
        {
            new BLLProductAnswer().Delete(id);
            this.Bind_gvList();
        }
    }
}
